home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / fs / fsAttributes.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-02  |  7.1 KB  |  218 lines

  1. /*
  2.  * fsAttributes.c --
  3.  *
  4.  *    This has procedures for operations done on file attributes.
  5.  *    The general strategy when getting attributes is to make one call to
  6.  *    the name server to get an initial version of the attributes, and
  7.  *    then make another call to the I/O server to update things like
  8.  *    the access time and modify time.  There are two ways to get to
  9.  *    the name server, either via a pathname or an open file.  The
  10.  *    I/O server is always contacted using a fileID.
  11.  *
  12.  * Copyright 1987 Regents of the University of California
  13.  * All rights reserved.
  14.  * Permission to use, copy, modify, and distribute this
  15.  * software and its documentation for any purpose and without
  16.  * fee is hereby granted, provided that the above copyright
  17.  * notice appear in all copies.  The University of California
  18.  * makes no representations about the suitability of this
  19.  * software for any purpose.  It is provided "as is" without
  20.  * express or implied warranty.
  21.  */
  22.  
  23. #ifndef lint
  24. static char rcsid[] = "$Header: /sprite/src/kernel/fs/RCS/fsAttributes.c,v 9.3 91/02/01 16:28:31 shirriff Exp $ SPRITE (Berkeley)";
  25. #endif not lint
  26.  
  27.  
  28. #include <sprite.h>
  29. #include <fs.h>
  30. #include <fsutil.h>
  31. #include <fsNameOps.h>
  32. #include <fslcl.h>
  33. #include <fsconsist.h>
  34. #include <fscache.h>
  35. #include <fsdm.h>
  36. #include <fsStat.h>
  37. #include <rpc.h>
  38.  
  39. #include <stdio.h>
  40.  
  41.  
  42. /*
  43.  *----------------------------------------------------------------------
  44.  *
  45.  * Fs_GetAttrStream --
  46.  *
  47.  *    Get the attributes of an open file.  The name server for the
  48.  *    file (if any, anonymous pipes won't have one) is contacted
  49.  *    to get the initial version of the attributes.  This includes
  50.  *    ownership, permissions, and a guess as to the size.  Then
  51.  *    a stream-specific call is made to update the attributes
  52.  *    from info at the I/O server.  For example, there may be
  53.  *    more up-to-date access and modify times at the I/O server.
  54.  *
  55.  * Results:
  56.  *    An error code and the attibutes.
  57.  *
  58.  * Side effects:
  59.  *    None.
  60.  *
  61.  *----------------------------------------------------------------------
  62.  */
  63.  
  64. ReturnStatus
  65. Fs_GetAttrStream(streamPtr, attrPtr)
  66.     Fs_Stream *streamPtr;
  67.     Fs_Attributes *attrPtr;
  68. {
  69.     register ReturnStatus    status;
  70.     register Fs_HandleHeader    *hdrPtr = streamPtr->ioHandlePtr;
  71.     register Fs_NameInfo        *nameInfoPtr = streamPtr->nameInfoPtr;
  72.  
  73.     if (!Fsutil_HandleValid(hdrPtr)) {
  74.     status = FS_STALE_HANDLE;
  75.     } else {
  76.     if (nameInfoPtr == (Fs_NameInfo *)NIL) {
  77.         /*
  78.          * Anonymous pipes have no name info.
  79.          */
  80.         bzero((Address)attrPtr, sizeof(Fs_Attributes));
  81.         status = SUCCESS;
  82.     } else {
  83.         /*
  84.          * Get the initial version of the attributes from the file server
  85.          * that has the name of the file.
  86.          */
  87. #ifdef SOSP91
  88.         int hostID, userID;
  89.         userID = Proc_GetEffectiveProc()->userID;
  90.         if (Proc_GetEffectiveProc()->genFlags & PROC_FOREIGN) {
  91.         hostID = Proc_GetEffectiveProc()->peerHostID;
  92.         } else {
  93.         hostID = rpc_SpriteID;
  94.         }
  95.         status = (*fs_AttrOpTable[nameInfoPtr->domainType].getAttr)
  96.             (&nameInfoPtr->fileID, rpc_SpriteID, attrPtr, hostID,
  97.             userID);
  98. #else
  99.         status = (*fs_AttrOpTable[nameInfoPtr->domainType].getAttr)
  100.             (&nameInfoPtr->fileID, rpc_SpriteID, attrPtr);
  101. #endif
  102. #ifdef lint
  103.         status = FslclGetAttr(&nameInfoPtr->fileID, rpc_SpriteID,attrPtr);
  104.         status = FsrmtGetAttr(&nameInfoPtr->fileID,rpc_SpriteID,attrPtr);
  105.         status = FspdevPseudoGetAttr(&nameInfoPtr->fileID,rpc_SpriteID,attrPtr);
  106. #endif lint
  107.         if (status != SUCCESS) {
  108.         printf(
  109.             "Fs_GetAttrStream: can't get name attributes <%x> for %s\n",
  110.             status, Fsutil_GetFileName(streamPtr));
  111.         }
  112.     }
  113.     if (status == SUCCESS) {
  114.         /*
  115.          * Update the attributes by contacting the I/O server.
  116.          */
  117.         fs_Stats.cltName.getIOAttrs++;
  118.         status = (*fsio_StreamOpTable[hdrPtr->fileID.type].getIOAttr)
  119.             (&hdrPtr->fileID, rpc_SpriteID, attrPtr);
  120. #ifdef lint
  121.         status = Fsrmt_GetIOAttr(&hdrPtr->fileID, rpc_SpriteID, attrPtr);
  122.         status = FsrmtFileGetIOAttr(&hdrPtr->fileID, rpc_SpriteID, attrPtr);
  123.         status = Fsio_DeviceGetIOAttr(&hdrPtr->fileID, rpc_SpriteID, attrPtr);
  124.         status = Fsio_PipeGetIOAttr(&hdrPtr->fileID, rpc_SpriteID, attrPtr);
  125.         status = FsRmtControlGetIOAttr(&hdrPtr->fileID, rpc_SpriteID,
  126.             attrPtr);
  127.         status = FspdevControlGetIOAttr(&hdrPtr->fileID, rpc_SpriteID,
  128.             attrPtr);
  129. #endif lint
  130.     }
  131.     fs_Stats.cltName.getAttrIDs++;
  132.     }
  133.     return(status);
  134. }
  135.  
  136. /*
  137.  *----------------------------------------------------------------------
  138.  *
  139.  * Fs_SetAttrStream --
  140.  *
  141.  *    Set the attributes of an open file.  First the name server is
  142.  *    contacted to verify permissions and to update the file descriptor.
  143.  *    Then the I/O server is contacted to update any cached attributes.
  144.  *
  145.  * Results:
  146.  *    An error code.
  147.  *
  148.  * Side effects:
  149.  *    The modify and access times are set.
  150.  *    The owner and group ID are set.
  151.  *    The permission bits are set.
  152.  *     If the operation is successful, the count of setAttrs is incremented.
  153.  *
  154.  *----------------------------------------------------------------------
  155.  */
  156.  
  157. ReturnStatus
  158. Fs_SetAttrStream(streamPtr, attrPtr, idPtr, flags)
  159.     Fs_Stream *streamPtr;    /* References file to manipulate. */
  160.     Fs_Attributes *attrPtr;    /* Attributes to give to the file. */
  161.     Fs_UserIDs *idPtr;        /* Owner and groups of calling process */
  162.     int flags;            /* Specify what attributes to set. */
  163. {
  164.     register ReturnStatus    status;
  165.     register Fs_HandleHeader    *hdrPtr = streamPtr->ioHandlePtr;
  166.     register Fs_NameInfo        *nameInfoPtr = streamPtr->nameInfoPtr;
  167.  
  168.     if (!Fsutil_HandleValid(hdrPtr)) {
  169.     status = FS_STALE_HANDLE;
  170.     } else {
  171.     if (streamPtr->nameInfoPtr != (Fs_NameInfo *)NIL) {
  172.         /*
  173.          * Set the attributes at the name server.
  174.          */
  175. #ifdef SOSP91
  176.         int hostID, userID;
  177.         userID = Proc_GetEffectiveProc()->userID;
  178.         if (Proc_GetEffectiveProc()->genFlags & PROC_FOREIGN) {
  179.         hostID = Proc_GetEffectiveProc()->peerHostID;
  180.         } else {
  181.         hostID = rpc_SpriteID;
  182.         }
  183.         status = (*fs_AttrOpTable[nameInfoPtr->domainType].setAttr)
  184.             (&nameInfoPtr->fileID, attrPtr, idPtr, flags,
  185.             rpc_SpriteID, hostID, userID);
  186. #else
  187.         status = (*fs_AttrOpTable[nameInfoPtr->domainType].setAttr)
  188.             (&nameInfoPtr->fileID, attrPtr, idPtr, flags);
  189. #endif
  190. #ifdef lint
  191.         status = FslclSetAttr(&nameInfoPtr->fileID, attrPtr,idPtr,flags);
  192.         status = FsrmtSetAttr(&nameInfoPtr->fileID, attrPtr,idPtr,flags);
  193.         status = FspdevPseudoSetAttr(&nameInfoPtr->fileID, attrPtr,idPtr,flags);
  194. #endif lint
  195.     } else {
  196.         status = SUCCESS;
  197.     }
  198.     if (status == SUCCESS) {
  199.         /*
  200.          * Set the attributes at the I/O server.
  201.          */
  202.         fs_Stats.cltName.setIOAttrs++;
  203.         status = (*fsio_StreamOpTable[hdrPtr->fileID.type].setIOAttr)
  204.             (&hdrPtr->fileID, attrPtr, flags);
  205. #ifdef lint
  206.         status = Fsrmt_SetIOAttr(&hdrPtr->fileID, attrPtr, flags);
  207.         status = FsrmtFileSetIOAttr(&hdrPtr->fileID, attrPtr, flags);
  208.         status = Fsio_DeviceSetIOAttr(&hdrPtr->fileID, attrPtr, flags);
  209.         status = Fsio_PipeSetIOAttr(&hdrPtr->fileID, attrPtr, flags);
  210.         status = FsRmtControlSetIOAttr(&hdrPtr->fileID, attrPtr, flags);
  211.         status = FspdevControlSetIOAttr(&hdrPtr->fileID, attrPtr, flags);
  212. #endif lint
  213.     }
  214.     fs_Stats.cltName.setAttrIDs++;
  215.     }
  216.     return(status);
  217. }
  218.